package com.huluobo.a2206douyindemo.register;

import androidx.lifecycle.MutableLiveData;

import com.google.gson.Gson;
import com.huluobo.base.bean.UserBeanResult;
import com.huluobo.base.mvvm.BaseViewModel;
import com.huluobo.base.net.Const;

import java.util.HashMap;
import java.util.Map;

import okhttp3.MediaType;
import okhttp3.RequestBody;

/**
 * Created by LC on 2024/8/15.
 */
public class RegisterViewModel extends BaseViewModel<RegisterRepo> {

    MutableLiveData<UserBeanResult> success = new MutableLiveData<>();

    MutableLiveData<String> failed = new MutableLiveData<>();

    public void register(String username, String password, String rePassword) {
        Map<String, String> map = new HashMap<>();
        map.put(Const.PARAM_USERNAME, username);
        map.put(Const.PARAM_PASSWORD, password);
        map.put(Const.PARAM_RE_PASSWORD, rePassword);

        String json = new Gson().toJson(map);
        RequestBody body = RequestBody.create(MediaType.parse(Const.MEDIA_TYPE), json);
        repo.register(body, success, failed);
    }

    @Override
    protected RegisterRepo createRepo() {
        return new RegisterRepo();
    }
}
